package cn.itsource.test.sand.demo;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

/**
 * @author : 张金铭
 * @description :
 * @create :2023-02-24 19:00:00
 */
@Slf4j
@Component
public class Demo {

    public static void main(String[] args) {
        String uuid = UUID.randomUUID().toString();
        // 随机生成经度在-180~180之间的数值
        double longitude = -180 + new Random().nextDouble() * 360;
        // 随机生成纬度在-90~90之间的数值
        double latitude = -90 + new Random().nextDouble() * 180;
        // 将经度和纬度拼接为字符串
        String coordinates = String.format("%.6f,%.6f", latitude, longitude);
        //117.1 - 118.6   24.0 -25.0

        String latLon = "24.0123456,117.712456";



        //请求body json
        String infojson = "{\n" +
                "\t\"lockId\": \"testLockId\",\n" +
                "\t\"companyId\": \"testCompanyId\",\n" +
                "\t\"qMark\": \"testQMark\",\n" +
                "\t\"updateTime\": \""+ LocalDateTime.now()+"\",\n" +
                "\t\"id\": \""+uuid+"\",\n" +
                "\t\"launchDate\": \"2023-03-31\",\n" +
                "\t\"bicycleId\": \""+uuid+"\",\n" +
                "\t\"licenseId\": \"testLicenseId\",\n" +
                "\t\"isInCity\": 1,\n" +
                "\t\"status\": 0\n" +
                "}";

        String stateJson = "{\n" +
                "  \"id\": \""+uuid+"\",\n" +
                "  \"companyId\": \"testCompanyId\",\n" +
                "  \"bicycleId\": \""+uuid+"\",\n" +
                "  \"latLon\": \""+latLon+"\",\n" +
                "  \"lockStatus\": 0,\n" +
                "  \"lodgingState\": 1,\n" +
                "  \"createdOn\": \""+LocalDateTime.now().toString()+"\",\n" +
                "  \"updateTime\": \""+LocalDateTime.now().toString()+"\"\n" +
                "}";

        String infoJsonList = "{\"infoList\":[{\n" +
                "\t\"lockId\": \"testLockId\",\n" +
                "\t\"companyId\": \"testCompanyId\",\n" +
                "\t\"qMark\": \"testQMark\",\n" +
                "\t\"updateTime\": \""+new Date()+"\",\n" +
                "\t\"id\": \""+UUID.randomUUID().toString()+"\",\n" +
                "\t\"launchDate\": \"2023-03-31\",\n" +
                "\t\"bicycleId\": \""+uuid+"\",\n" +
                "\t\"licenseId\": \"testLicenseId\",\n" +
                "\t\"isInCity\": 1,\n" +
                "\t\"status\": 0,\n" +
                "\t\"statusName\": \"test\",\n" +
                "},"+
                "{\n" +
                "\t\"lockId\": \"testLockId\",\n" +
                "\t\"companyId\": \"testCompanyId\",\n" +
                "\t\"qMark\": \"testQMark\",\n" +
                "\t\"updateTime\": \""+new Date() +"\",\n" +
                "\t\"id\": \""+UUID.randomUUID().toString()+"\",\n" +
                "\t\"launchDate\": \"2023-03-31\",\n" +
                "\t\"bicycleId\": \""+uuid+"\",\n" +
                "\t\"licenseId\": \"testLicenseId\",\n" +
                "\t\"isInCity\": 1,\n" +
                "\t\"status\": 0\n" +
                "},\n" +
                "]\n" +
                "}";





        String stateJsonList = "{\"stateList\": [{\n" +
                "\t\"companyId\": \"testCompanyId\",\n" +
                "\t\"lodgingState\": 0,\n" +
                "\t\"latLon\": \"24.025345,117.707811\",\n" +
                "\t\"lockStatus\": 1,\n" +
                "\t\"updateTime\": \""+LocalDateTime.now().toString()+"\",\n" +
                "\t\"id\": \""+UUID.randomUUID().toString()+"\",\n" +
                "\t\"bicycleId\": \"b7472b0c-cda7-43b7-b536-9e4b55306b15\",\n" +
                "\t\"createdOn\": \""+LocalDateTime.now().toString()+"\"\n" +
                "},\n" +
                "{\n" +
                "\t\"companyId\": \"testCompanyId\",\n" +
                "\t\"lodgingState\": 0,\n" +
                "\t\"latLon\": \"24.025345,117.707811\",\n" +
                "\t\"lockStatus\": 1,\n" +
                "\t\"updateTime\": \"2023-04-17T15:13:30.519\",\n" +
                "\t\"id\": \""+UUID.randomUUID().toString()+"\",\n" +
                "\t\"bicycleId\": \"b7472b0c-cda7-43b7-b536-9e4b55306b15\",\n" +
                "\t\"createdOn\": \"2023-04-17T15:13:30.519\"\n" +
                "},\n" +
                "]\n" +
                "}";

        String stateNewestJsonList = "{\n" +
                "\t\"infoElectricList\": [{\n" +
                "\t\t\"id\": \"38689621,qingju68dd2a03e\",\n" +
                "\t\t\"bicycleId\": \"38689621\",\n" +
                "\t\t\"companyId\": \"qingju68dd2a03e\",\n" +
                "\t\t\"latLon\": \"24.471312,117.984321\",\n" +
                "\t\t\"latLon2\": \"24.471312,117.984321\",\n" +
                "\t\t\"lockStatus\": 1,\n" +
                "\t\t\"lodgingState\": 0,\n" +
                "\t\t\"count\": 0,\n" +
                "\t\t\"updateTime\": \"2022-07-01 02:44:01\",\n" +
                "\t\t\"calculateTime\": \"2022-07-01 02:44:08\",\n" +
                "\t\t\"isInCity\": 0,\n" +
                "\t\t\"isInCityBicycle\": 1,\n" +
                "\t\t\"isInCityBreakRule\": 1,\n" +
                "\t\t\"jtqyId\": null,\n" +
                "\t\t\"jtqyName\": null,\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"areaCode\": \"350205\",\n" +
                "\t\t\"importantAreaId\": \"5f1f4677-e954-478a-a726-14012040ad1e\",\n" +
                "\t\t\"dzwlId\": null\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"40612201,qingju68dd2a03e\",\n" +
                "\t\t\"bicycleId\": \"40612201\",\n" +
                "\t\t\"companyId\": \"qingju68dd2a03e\",\n" +
                "\t\t\"latLon\": \"24.471263,117.984303\",\n" +
                "\t\t\"latLon2\": \"24.471263,117.984303\",\n" +
                "\t\t\"lockStatus\": 1,\n" +
                "\t\t\"lodgingState\": 0,\n" +
                "\t\t\"count\": 0,\n" +
                "\t\t\"updateTime\": \"2022-07-01 02:47:03\",\n" +
                "\t\t\"calculateTime\": \"2022-07-01 02:47:08\",\n" +
                "\t\t\"isInCity\": 0,\n" +
                "\t\t\"isInCityBicycle\": 1,\n" +
                "\t\t\"isInCityBreakRule\": 1,\n" +
                "\t\t\"jtqyId\": null,\n" +
                "\t\t\"jtqyName\": null,\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"areaCode\": \"350205\",\n" +
                "\t\t\"importantAreaId\": \"5f1f4677-e954-478a-a726-14012040ad1e\",\n" +
                "\t\t\"dzwlId\": null\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"40690995,qingju68dd2a03e\",\n" +
                "\t\t\"bicycleId\": \"40690995\",\n" +
                "\t\t\"companyId\": \"qingju68dd2a03e\",\n" +
                "\t\t\"latLon\": \"24.471239,117.98427\",\n" +
                "\t\t\"latLon2\": \"24.471239,117.98427\",\n" +
                "\t\t\"lockStatus\": 1,\n" +
                "\t\t\"lodgingState\": 0,\n" +
                "\t\t\"count\": 0,\n" +
                "\t\t\"updateTime\": \"2022-07-01 02:52:13\",\n" +
                "\t\t\"calculateTime\": \"2022-07-01 02:52:38\",\n" +
                "\t\t\"isInCity\": 0,\n" +
                "\t\t\"isInCityBicycle\": 1,\n" +
                "\t\t\"isInCityBreakRule\": 1,\n" +
                "\t\t\"jtqyId\": null,\n" +
                "\t\t\"jtqyName\": null,\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"areaCode\": \"350205\",\n" +
                "\t\t\"importantAreaId\": \"5f1f4677-e954-478a-a726-14012040ad1e\",\n" +
                "\t\t\"dzwlId\": null\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"40669579,qingju68dd2a03e\",\n" +
                "\t\t\"bicycleId\": \"40669579\",\n" +
                "\t\t\"companyId\": \"qingju68dd2a03e\",\n" +
                "\t\t\"latLon\": \"24.471315,117.984278\",\n" +
                "\t\t\"latLon2\": \"24.471315,117.984278\",\n" +
                "\t\t\"lockStatus\": 1,\n" +
                "\t\t\"lodgingState\": 0,\n" +
                "\t\t\"count\": 0,\n" +
                "\t\t\"updateTime\": \"2022-07-01 02:52:36\",\n" +
                "\t\t\"calculateTime\": \"2022-07-01 02:53:08\",\n" +
                "\t\t\"isInCity\": 0,\n" +
                "\t\t\"isInCityBicycle\": 1,\n" +
                "\t\t\"isInCityBreakRule\": 1,\n" +
                "\t\t\"jtqyId\": null,\n" +
                "\t\t\"jtqyName\": null,\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"areaCode\": \"350205\",\n" +
                "\t\t\"importantAreaId\": null,\n" +
                "\t\t\"dzwlId\": null\n" +
                "\t}, {\n" +
                "\t\t\"id\": \"40632925,qingju68dd2a03e\",\n" +
                "\t\t\"bicycleId\": \"40632925\",\n" +
                "\t\t\"companyId\": \"qingju68dd2a03e\",\n" +
                "\t\t\"latLon\": \"24.471292,117.984284\",\n" +
                "\t\t\"latLon2\": \"24.471292,117.984284\",\n" +
                "\t\t\"lockStatus\": 1,\n" +
                "\t\t\"lodgingState\": 0,\n" +
                "\t\t\"count\": 0,\n" +
                "\t\t\"updateTime\": \"2022-07-01 02:57:35\",\n" +
                "\t\t\"calculateTime\": \"2022-07-01 02:58:08\",\n" +
                "\t\t\"isInCity\": 0,\n" +
                "\t\t\"isInCityBicycle\": 1,\n" +
                "\t\t\"isInCityBreakRule\": 1,\n" +
                "\t\t\"jtqyId\": null,\n" +
                "\t\t\"jtqyName\": null,\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"areaCode\": \"350205\",\n" +
                "\t\t\"importantAreaId\": \"5f1f4677-e954-478a-a726-14012040ad1e\",\n" +
                "\t\t\"dzwlId\": null\n" +
                "\t}]\n" +
                "}";


        String testPe = "{\n" +
                "\t\"sendUserId\": \"984\",\n" +
                "\t\"sendOfficeId\": \"1459999990221\",\n" +
                "\t\"sendOpinion\": \"请 思明区( 公共安全工作指令【三级】 ) 主办 \",\n" +
                "\t\"sourcePid\": \"8a8a848b88b912730188b91381220041\",\n" +
                "\t\"submitType\": \"00\",\n" +
                "\t\"taskUrl\": \"http://192.168.1.232:1199//#/detailInfo?id=8a8a848b88b912730188b91381220041&flowName=线索办理&packageName=公共安全&formId=8a8a848b88b912730188b9143b370071&workItemId=8a8a848b88b912730188b9144ad8007a\",\n" +
                "\t\"sourceTaskId\": \"8a8a848b88b912730188b9143b370071\",\n" +
                "\t\"handlers\": [{\n" +
                "\t\t\"userId\": \"1145\",\n" +
                "\t\t\"userName\": \"测试2\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"2753\",\n" +
                "\t\t\"userName\": \"李祥浪\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"217\",\n" +
                "\t\t\"userName\": \"测试9\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1318\",\n" +
                "\t\t\"userName\": \"张建斌\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"2588\",\n" +
                "\t\t\"userName\": \"思明\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"632\",\n" +
                "\t\t\"userName\": \"詹雅伦\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"555\",\n" +
                "\t\t\"userName\": \"方根\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"556\",\n" +
                "\t\t\"userName\": \"刘阳\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1481\",\n" +
                "\t\t\"userName\": \"王日桥\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"402810828408c601018409602d69108a\",\n" +
                "\t\t\"userName\": \"林夕\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1009\",\n" +
                "\t\t\"userName\": \"张汉城\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1711\",\n" +
                "\t\t\"userName\": \"叶志明\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1138\",\n" +
                "\t\t\"userName\": \"施志华\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"750\",\n" +
                "\t\t\"userName\": \"郭丙转\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"749\",\n" +
                "\t\t\"userName\": \"郭泽国\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1141\",\n" +
                "\t\t\"userName\": \"颜世明\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1479\",\n" +
                "\t\t\"userName\": \"林森能\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1480\",\n" +
                "\t\t\"userName\": \"骆远帆\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"1557\",\n" +
                "\t\t\"userName\": \"黄文胜\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}, {\n" +
                "\t\t\"userId\": \"2988\",\n" +
                "\t\t\"userName\": \"施志聪\",\n" +
                "\t\t\"officeId\": \"1459841363562\",\n" +
                "\t\t\"officeName\": \"思明区\"\n" +
                "\t}],\n" +
                "\t\"sendOfficeName\": \"1459999990221\",\n" +
                "\t\"sendUserName\": \"郭美凤\",\n" +
                "\t\"sendTime\": \"2023-06-14T16:44:50\"\n" +
                "}";

        String sup = "{\n" +
                "\t\"sourceSysCode\": \"ywtg\",\n" +
                "\t\"sourcePid\": \"2c9f808288b94bd80188bd9e2c2452fe\",\n" +
                "\t\"sourceTaskId\": \"2c9f808288b94bd80188bd9faad753b8\",\n" +
                "\t\"opType\": \"START\",\n" +
                "\t\"supervise\": {\n" +
                "\t\t\"itemCode\": \"CaseFeedback\",\n" +
                "\t\t\"startTime\": \"2023-06-15 13:55:38\",\n" +
                "\t\t\"deadline\": \"2023-07-27 13:55:38\",\n" +
                "\t\t\"warningTime\": \"2023-07-19 13:55:38\"\n" +
                "\t}\n" +
                "}";


        String time = String.valueOf(System.currentTimeMillis());
        String result2 = HttpRequest.post("http://localhost:99/open/getSign")
                .header("X-apiKey", "ywtg")//头信息，多个头信息多次调用此方法即可
                .header("X-nonce",uuid)
                .header("X-timestamp",time)
                .body(sup).execute().body();
        Object data = JSONObject.parseObject(result2).get("data");
        String str = JSON.toJSONString(data);
        Map map = JSON.parseObject(str, Map.class);
        String sign = String.valueOf(map.get("sign"));
        System.out.println("签名为："+sign);


        String result3InfoUrl = "http://localhost:10090/open/BicycleInfoUpload";
        String result3StateUrl = "http://localhost:10090/open/BicycleStateUpload";
        String result3StateNewUrl = "http://localhost:10090/open/BicycleStateNewestUpload";
        String result3EInfoUrl = "http://localhost:10090/open/BicycleInfoElectricUpload";
        String testPeUrl = "http://localhost:99/open/Supervise";
        String result3 = HttpRequest.post(testPeUrl)
                .header("X-apiKey", "ywtg")//头信息，多个头信息多次调用此方法即可
                .header("X-nonce",uuid)
                .header("X-timestamp",time)
                .header("X-apiSecret","jbUd4y7C")
                .header("X-sign",sign)
                .body(sup).execute().body();
        System.out.println(result3);
    }
}
